package com.oop.ch08;

public class User {
	private String name;
	private int age;
	private String sex;
	
	
	@Override
	public String toString() {
		return "User{" + "name='" + name + '\'' + ", age=" + age + ", sex='" + sex + '\'' + '}';
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public int getAge() {
		return age;
	}
	
	public void setAge(int age) throws Exception{
		if(age>=1 && age<=100){
			this.age = age;
		}else {
			//手动抛出错误
			throw new Exception("年龄设置不合法：年龄应在1-100之间");
		}
		
	}
	
	public String getSex() {
		return sex;
	}
	
	public void setSex(String sex) {
		this.sex = sex;
	}
}
